package top.sdaily.business.controller.crm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.core.mybatis.Page;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.business.model.crm.Customer;
import top.sdaily.business.service.crm.CustomerService;

import java.util.List;

/**
 * Created by tsujishiki on 2017/1/22.
 */
@RestController
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public ReturnBody getPage(Page page) {
        List<Customer> customerList = customerService.getPageCustomer(page);
        return ReturnBody.success().setData(customerList).setPage(page);
    }

    @GetMapping(value = "/{id}")
    public ReturnBody getCustomerById(@PathVariable String id) {
        return ReturnBody.success().setData(customerService.getCustomerById(id));
    }

    @PostMapping
    public ReturnBody addCustomer(@RequestBody Customer customer) {
        customerService.insertCustomer(customer);
        return ReturnBody.success();
    }

    @PutMapping
    public ReturnBody updateCustomer(@RequestBody Customer customer) {
        customerService.updateCustomer(customer);
        return ReturnBody.success();
    }

    @RequestMapping(value = "/enabled/{condition}", method = RequestMethod.GET)
    public ReturnBody getAllEnabledCustomers(@PathVariable String condition) {
        return ReturnBody.success().setData(customerService.getAllEnabledCustomer(condition));
    }
}
